<template>
    <div>
        <h3>等级显示列表</h3>
        <br>
        <a href="/leveradd">等级添加</a>
        <br>
        会员等级:
        <input type="text" v-model="page.name">
        会员权益：
        <input type="text" v-model="page.qname">

         <input type="button" value="查询" @click="show">
         <input type="button" value="清空" @click="qing">
        
        <table class="table">
            <thead>
                <tr>
                    <th>会员编号</th>
                    <th>会员等级</th>
                    <th>会员权益</th>
                    <th>会员权益数量</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody v-for="d in data">
                <tr>
                    <td>{{d.lId}}</td>
                    <td>{{d.dname}}</td>
                    
                    <td v-if="d.state==false" >{{}}</td>
                    <td v-if="d.state==true" >{{d.qname}}</td>

                    <td v-if="d.state==false" >{{0}}</td>
                    <td v-if="d.state==true" >{{d.quanCount}}</td>
                    <td>{{d.state?"启用":"禁用"}}</td>
                    <td>
                        <!-- <input type="button" value="修改" @click="updet(d.mid)"> -->
                        <input type="button" :value='d.state?"禁用":"启用"' @click="states(d.lId)">

                        
                    </td>

                </tr>
            </tbody>
        </table>
        一共{{sum.count}}条数据，页容量{{page.size}}条，
        共{{sum.pageCount}}页，目前第{{page.index}}页 
        <input type="button" value="首页" @click="fan(1)">
        <input type="button" value="上一页" @click="fan(page.index-1)">

        <input type="button" v-for="d in sum.pageCount"  :value="d" @click="fan(d)">

        <input type="button" value="下一页" @click="fan(page.index+1)">
        <input type="button" value="尾页" @click="fan(sum.pageCount)">
        页容量:
        <select v-model="page.size" @change="yer">
            <option value="3">===3===</option>
            <option value="4">===4===</option>
            <option value="5">===5===</option>
        </select>
        转到:
        <input type="number" v-model="page.index">
        <input type="button" value="跳转/页" @click="show" class="btn btn-success">
    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
const router=useRouter();
const route=useRoute();


// const updet=(val:any)=>{
//     router.push({path:"/update",query:{id:val}})
// }

const states=(val:any)=>{

    axios.get("https://localhost:7237/api/Deng/Stateup",{params:{id:val}}).then(res=>{
        if(res.data>0){
            alert('该等级已被禁用！权益清空')
            show()
        }
        else{
            alert('该用户已启用!')
        }
    })
}





//翻页
const fan=(e:any)=>{
    if(e>=1 && e<=sum.value.pageCount){
        page.value.index=e;
        show()
    }
}
const yer=()=>{
    page.value.index=1;
    show()
}

const data=ref([{
      "lId": 0,
      "dname": "",
      "quanCount": 0,
      "qname": "",
      "state": true
}])



const sum=ref({
    count:0,
    pageCount:0
})
const page=ref({
    name:"",
    qname:"",
    index:1,
    size:3
})
const show=()=>{
    axios.get("https://localhost:7237/api/Deng/DengShow",{params:page.value}).then(res=>{
        data.value=res.data.list;
        sum.value.count=res.data.datt;
        sum.value.pageCount=Math.ceil(sum.value.count/page.value.size)
    })
}

const qing=()=>{
    page.value.name="";
    page.value.qname="";
    show()
}

onMounted(()=>{
    show()

})

</script>

<style scoped>

</style>